import java.util.ArrayList;
import java.util.concurrent.Semaphore;

public class Player 
{
	GPSCoordinates position;
	ArrayList<Gesture> allowedGestures;
	ArrayList<Attribute> attributes;	
	ArrayList<Player> nearlyPlayers;
	String name;
	Semaphore playerSemaphore = new Semaphore(1);
	
	public Player(String name_)
	{
		nearlyPlayers = new ArrayList<Player>();
		name = name_;
		position = new GPSCoordinates( 0, 0);
		allowedGestures = new ArrayList<Gesture>();
		attributes = new ArrayList<Attribute>();
		for (Gesture gesture : LoadedGestures.getInstance().getGestures()) 
		{
			allowedGestures.add(gesture);
		}
		for (Attribute attrib : (LoadedAttributes.getInstance()).getAttributes()) 
		{
			attributes.add(attrib.clone());
		}
	}
	
	public Gesture gestureIsEnabled(String description)
	{
		for (Gesture gest : allowedGestures) 
		{
			if(gest.toString().equals(description))
			{
				return gest;
			}
		}
		return null;
	}
	
	public Attribute getAttribute(Attribute attrib)
	{
		int index =attributes.indexOf(attrib);
		return attributes.get(index);
	}
	
	public Attribute getAttribute(String name)
	{
		Attribute tmpAtr = new Attribute(name, 0, false);
		int index =attributes.indexOf(tmpAtr);
		if(index < 0)
		{
			return null;
		}
		return attributes.get(index);
	}
	
	public boolean equals(Object object)
	{
		Player rv = (Player)object;
		if(rv == null)
		{
			return false;
		}
		return name.equals(rv.name);
	}
};
